﻿Ext.define('Oa.AnnualGrid', {
    extend: 'Ext.grid.Panel',
    alias: 'Widget.AnnualGrid',

    // override
    initComponent: function () {
        var store = Ext.create('Ext.data.TreeStore', {
            model: 'TreeModel',
            proxy: {
                type: 'ajax',
                url: '/dept.mvc/DeptTreeByEmp',
                extraParams: {
                    controllerName: 'Annual'
                },
                reader: {
                    type: 'json'
                }
            },
            // 设置根节点
            root: {
                expanded: true
            },
            autoLoad: true
        });

        this.columns = [{
            header: "部门",flex:1,
            dataIndex: 'dep'
        }, {
            header: "姓名", flex: 1,
            dataIndex: 'name'
        }, {
            header: "首次工作日期", flex: 1,
            dataIndex: 'fristwork',
            renderer: function (value) {
                return value.replace(" 0:00:00","");
            }
        }, {
            header: "入职日期", flex: 1,
            dataIndex: 'trialDate',
            renderer: function (value) {
                return value.replace(" 0:00:00", "");
            }
        }, {
            header: "总工龄", flex: 1,
            dataIndex: 'sumworkdays'
        }, {
            header: "是否满一年",flex:1,
            dataIndex: 'onemoreyear'
        }, {
            header: "年假数",flex:1,
            dataIndex: 'annualwork'
        }, {
            header: "已休天数",flex:1,
            dataIndex: 'hadused',
            renderer: function (value) {
                if (value == "")
                    return 0;
                else
                    return value;
            }
        }];
        // Set up a model to use in our Store
        Ext.define('AnnualModel', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'dep'
            }, {
                name: 'name'
            }, {
                name: 'fristwork'
            }, {
                name: 'trialDate'
            }, {
                name: 'sumworkdays'
            }, {
                name: 'onemoreyear'
            }, {
                name: 'annualwork'
            }, {
                name: 'hadused'
            }]
        });

        var ds = Ext.create('Ext.data.Store', {
            model: 'AnnualModel',
            pageSize: 20, // items per page
            proxy: {
                type: 'ajax',
                url: '/Annual.mvc/Find',
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'totalCount'//分页使用
                }
            },
            autoLoad: false
        });
        ds.load({ params: { start: 0, limit: 20} });
        ds.on('beforeload', function (thiz, options) {
            Ext.apply(thiz.proxy.extraParams, { idStr: Ext.getCmp('treeDeptAnnual').getValue(), name: Ext.getCmp('txtNameAnnual').getValue() });
        });
        this.store = ds;

        this.dockedItems = [{
            xtype: 'toolbar',
            dock: 'top',
            items: [{
                xtype: 'tbtext',
                text: '部门:'
            }, {
                xtype: 'treepicker',
                id: 'treeDeptAnnual',
                displayField: 'text',
                forceSelection: true,
                editable: false,
                width: 250,
                store: store
            }, {
                xtype: 'tbtext',
                text: '姓名:'
            }, {
                xtype: 'textfield',
                id: 'txtNameAnnual',
                emptyText: '人名的一或几个字',
                blankText: '人名的一或几个字',
                anchor: '100%'
            }, {
                text: "查询",
                iconCls: 'icon-search',
                handler: function () {
                    Ext.getCmp('pagingAnnual').moveFirst();
                }
            }]
        }, {
            xtype: 'pagingtoolbar',
            id: 'pagingAnnual',
            store: ds,
            dock: 'bottom',
            displayInfo: true
        }];

        // finally call the superclasses implementation
        Oa.AnnualGrid.superclass.initComponent.call(this);
    }
});